package com.guzhen.wallpager;

import android.os.Build.VERSION;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class RomUtils {
    public static class RomInfo {
        private String name;
        private String version;

        public String getName() {
            return this.name;
        }

        public String getVersion() {
            return this.version;
        }

        @Override
        public String toString() {
            return "RomInfo{name=" + this.name + ", version=" + this.version + "}";
        }
    }

    private static String[] ROM_360 = null;
    private static String[] ROM_COOLPAD = null;
    private static String[] ROM_GIONEE = null;
    private static String[] ROM_GOOGLE = null;
    private static String[] ROM_HTC = null;
    private static String[] ROM_HUAWEI = null;
    private static String[] ROM_LEECO = null;
    private static String[] ROM_LENOVO = null;
    private static String[] ROM_LG = null;
    private static String[] ROM_MEIZU = null;
    private static String[] ROM_MOTOROLA = null;
    private static String[] ROM_NUBIA = null;
    private static String[] ROM_ONEPLUS = null;
    private static String[] ROM_OPPO = null;
    private static String[] ROM_SAMSUNG = null;
    private static String[] ROM_SMARTISAN = null;
    private static String[] ROM_SONY = null;
    private static String[] ROM_VIVO = null;
    private static String[] ROM_XIAOMI = null;
    private static String[] ROM_ZTE = null;
    private static String UNKNOWN = "unknown";
    private static String VERSION_PROPERTY_360 = "ro.build.uiversion";
    private static String VERSION_PROPERTY_HUAWEI = "ro.build.version.emui";
    private static String VERSION_PROPERTY_LEECO = "ro.letv.release.version";
    private static String VERSION_PROPERTY_NUBIA = "ro.build.rom.id";
    private static String VERSION_PROPERTY_ONEPLUS = "ro.rom.version";
    private static String VERSION_PROPERTY_OPPO = "ro.build.version.opporom";
    private static String VERSION_PROPERTY_VIVO = "ro.vivo.os.build.display.id";
    private static String VERSION_PROPERTY_XIAOMI = "ro.build.version.incremental";
    private static String VERSION_PROPERTY_ZTE = "ro.build.MiFavor_version";
    private static RomInfo bean;

    static {
        RomUtils.ROM_HUAWEI = new String[]{"huawei"};
        RomUtils.ROM_VIVO = new String[]{"vivo"};
        RomUtils.ROM_XIAOMI = new String[]{"xiaomi"};
        RomUtils.ROM_OPPO = new String[]{"oppo"};
        RomUtils.ROM_LEECO = new String[]{"leeco", "letv"};
        RomUtils.ROM_360 = new String[]{"360", "qiku"};
        RomUtils.ROM_ZTE = new String[]{"zte"};
        RomUtils.ROM_ONEPLUS = new String[]{"oneplus"};
        RomUtils.ROM_NUBIA = new String[]{"nubia"};
        RomUtils.ROM_COOLPAD = new String[]{"coolpad", "yulong"};
        RomUtils.ROM_LG = new String[]{"lg", "lge"};
        RomUtils.ROM_GOOGLE = new String[]{"google"};
        RomUtils.ROM_SAMSUNG = new String[]{"samsung"};
        RomUtils.ROM_MEIZU = new String[]{"meizu"};
        RomUtils.ROM_LENOVO = new String[]{"lenovo"};
        RomUtils.ROM_SMARTISAN = new String[]{"smartisan", "deltainno"};
        RomUtils.ROM_HTC = new String[]{"htc"};
        RomUtils.ROM_SONY = new String[]{"sony"};
        RomUtils.ROM_GIONEE = new String[]{"gionee", "amigo"};
        RomUtils.ROM_MOTOROLA = new String[]{"motorola"};
        RomUtils.bean = null;
    }

    private RomUtils() {
        throw new UnsupportedOperationException("u can\'t instantiate me...");
    }

    private static String getBrand() {
        try {
            String s = Build.BRAND;
            if(!TextUtils.isEmpty(s)) {
                return s.toLowerCase();
            }
        }
        catch(Throwable unused_ex) {
        }

        return "unknown";
    }

    private static String getManufacturer() {
        try {
            String s = Build.MANUFACTURER;
            if(!TextUtils.isEmpty(s)) {
                return s.toLowerCase();
            }
        }
        catch(Throwable unused_ex) {
        }

        return "unknown";
    }

    public static RomInfo getRomInfo() {
        RomInfo romUtils$RomInfo0 = RomUtils.bean;
        if(romUtils$RomInfo0 != null) {
            return romUtils$RomInfo0;
        }

        RomUtils.bean = new RomInfo();
        String s = RomUtils.getBrand();
        String s1 = RomUtils.getManufacturer();
        String[] arr_s = RomUtils.ROM_HUAWEI;
        if(RomUtils.isRightRom(s, s1, arr_s)) {
            RomUtils.bean.name = arr_s[0];
            String s2 = RomUtils.getRomVersion("ro.build.version.emui");
            String[] arr_s1 = s2.split("_");
            if(arr_s1.length > 1) {
                RomUtils.bean.version = arr_s1[1];
                return RomUtils.bean;
            }

            RomUtils.bean.version = s2;
            return RomUtils.bean;
        }

        String[] arr_s2 = RomUtils.ROM_VIVO;
        if(RomUtils.isRightRom(s, s1, arr_s2)) {
            RomUtils.bean.name = arr_s2[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.vivo.os.build.display.id");
            return RomUtils.bean;
        }

        String[] arr_s3 = RomUtils.ROM_XIAOMI;
        if(RomUtils.isRightRom(s, s1, arr_s3)) {
            RomUtils.bean.name = arr_s3[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.build.version.incremental");
            return RomUtils.bean;
        }

        String[] arr_s4 = RomUtils.ROM_OPPO;
        if(RomUtils.isRightRom(s, s1, arr_s4)) {
            RomUtils.bean.name = arr_s4[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.build.version.opporom");
            return RomUtils.bean;
        }

        String[] arr_s5 = RomUtils.ROM_LEECO;
        if(RomUtils.isRightRom(s, s1, arr_s5)) {
            RomUtils.bean.name = arr_s5[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.letv.release.version");
            return RomUtils.bean;
        }

        String[] arr_s6 = RomUtils.ROM_360;
        if(RomUtils.isRightRom(s, s1, arr_s6)) {
            RomUtils.bean.name = arr_s6[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.build.uiversion");
            return RomUtils.bean;
        }

        String[] arr_s7 = RomUtils.ROM_ZTE;
        if(RomUtils.isRightRom(s, s1, arr_s7)) {
            RomUtils.bean.name = arr_s7[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.build.MiFavor_version");
            return RomUtils.bean;
        }

        String[] arr_s8 = RomUtils.ROM_ONEPLUS;
        if(RomUtils.isRightRom(s, s1, arr_s8)) {
            RomUtils.bean.name = arr_s8[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.rom.version");
            return RomUtils.bean;
        }

        String[] arr_s9 = RomUtils.ROM_NUBIA;
        if(RomUtils.isRightRom(s, s1, arr_s9)) {
            RomUtils.bean.name = arr_s9[0];
            RomUtils.bean.version = RomUtils.getRomVersion("ro.build.rom.id");
            return RomUtils.bean;
        }

        String[] arr_s10 = RomUtils.ROM_COOLPAD;
        if(RomUtils.isRightRom(s, s1, arr_s10)) {
            RomUtils.bean.name = arr_s10[0];
        }
        else {
            String[] arr_s11 = RomUtils.ROM_LG;
            if(RomUtils.isRightRom(s, s1, arr_s11)) {
                RomUtils.bean.name = arr_s11[0];
            }
            else {
                String[] arr_s12 = RomUtils.ROM_GOOGLE;
                if(RomUtils.isRightRom(s, s1, arr_s12)) {
                    RomUtils.bean.name = arr_s12[0];
                }
                else {
                    String[] arr_s13 = RomUtils.ROM_SAMSUNG;
                    if(RomUtils.isRightRom(s, s1, arr_s13)) {
                        RomUtils.bean.name = arr_s13[0];
                    }
                    else {
                        String[] arr_s14 = RomUtils.ROM_MEIZU;
                        if(RomUtils.isRightRom(s, s1, arr_s14)) {
                            RomUtils.bean.name = arr_s14[0];
                        }
                        else {
                            String[] arr_s15 = RomUtils.ROM_LENOVO;
                            if(RomUtils.isRightRom(s, s1, arr_s15)) {
                                RomUtils.bean.name = arr_s15[0];
                            }
                            else {
                                String[] arr_s16 = RomUtils.ROM_SMARTISAN;
                                if(RomUtils.isRightRom(s, s1, arr_s16)) {
                                    RomUtils.bean.name = arr_s16[0];
                                }
                                else {
                                    String[] arr_s17 = RomUtils.ROM_HTC;
                                    if(RomUtils.isRightRom(s, s1, arr_s17)) {
                                        RomUtils.bean.name = arr_s17[0];
                                    }
                                    else {
                                        String[] arr_s18 = RomUtils.ROM_SONY;
                                        if(RomUtils.isRightRom(s, s1, arr_s18)) {
                                            RomUtils.bean.name = arr_s18[0];
                                        }
                                        else {
                                            String[] arr_s19 = RomUtils.ROM_GIONEE;
                                            if(RomUtils.isRightRom(s, s1, arr_s19)) {
                                                RomUtils.bean.name = arr_s19[0];
                                            }
                                            else {
                                                String[] arr_s20 = RomUtils.ROM_MOTOROLA;
                                                RomUtils.bean.name = RomUtils.isRightRom(s, s1, arr_s20) ? arr_s20[0] : s1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        RomUtils.bean.version = RomUtils.getRomVersion("");
        return RomUtils.bean;
    }

    private static String getRomVersion(String s) {
        String s1 = TextUtils.isEmpty(s) ? "" : RomUtils.getSystemProperty(s);
        if((TextUtils.isEmpty(s1)) || (s1.equals("unknown"))) {
            try {
                String s2 = Build.DISPLAY;
                if(!TextUtils.isEmpty(s2)) {
                    s1 = s2.toLowerCase();
                }
            }
            catch(Throwable unused_ex) {
            }
        }

        return TextUtils.isEmpty(s1) ? "unknown" : s1;
    }

    private static String getSystemProperty(String s) {
        String s1 = RomUtils.getSystemPropertyByShell(s);
        if(!TextUtils.isEmpty(s1)) {
            return s1;
        }

        String s2 = RomUtils.getSystemPropertyByStream(s);
        if(!TextUtils.isEmpty(s2)) {
            return s2;
        }

        return Build.VERSION.SDK_INT >= 28 ? s2 : RomUtils.getSystemPropertyByReflect(s);
    }

    private static String getSystemPropertyByReflect(String s) {
        try {
            Class class0 = Class.forName("android.os.SystemProperties");
            return (String)class0.getMethod("get", String.class, String.class).invoke(class0, s, "");
        }
        catch(Exception unused_ex) {
            return "";
        }
    }

    private static String getSystemPropertyByShell(String s) {
        String s1 = null;
        BufferedReader bufferedReader0 = null;
        try {
            bufferedReader0 = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("getprop " + s).getInputStream()), 0x400);
            s1 = bufferedReader0.readLine();
        }
        catch(IOException unused_ex) {
        }
        catch(Throwable throwable0) {
        }

        if(bufferedReader0 != null) {
            try {
                bufferedReader0.close();
            }
            catch(IOException unused_ex) {
            }

        }
        if(s1 != null) {
            return s1;
        }

        return "";
    }

    private static String getSystemPropertyByStream(String s) {
        try {
            Properties properties0 = new Properties();
            properties0.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
            return properties0.getProperty(s, "");
        }
        catch(Exception unused_ex) {
            return "";
        }
    }

    public static boolean is360() {
        return "360".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isCoolpad() {
        return "coolpad".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isGionee() {
        return "gionee".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isGoogle() {
        return "google".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isHtc() {
        return "htc".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isHuawei() {
        return "huawei".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isLeeco() {
        return "leeco".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isLenovo() {
        return "lenovo".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isLg() {
        return "lg".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isMeizu() {
        return "meizu".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isMotorola() {
        return "motorola".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isNubia() {
        return "nubia".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isOneplus() {
        return "oneplus".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isOppo() {
        return "oppo".equals(RomUtils.getRomInfo().name);
    }

    private static boolean isRightRom(String s, String s1, String[] arr_s) {
        int v = 0;
        while(v < arr_s.length) {
            String s2 = arr_s[v];
            if(!s.contains(s2) && !s1.contains(s2)) {
                ++v;
                continue;
            }

            return true;
        }

        return false;
    }

    public static boolean isSamsung() {
        return "samsung".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isSmartisan() {
        return "smartisan".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isSony() {
        return "sony".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isVivo() {
        return "vivo".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isXiaomi() {
        return "xiaomi".equals(RomUtils.getRomInfo().name);
    }

    public static boolean isZte() {
        return "zte".equals(RomUtils.getRomInfo().name);
    }
}

